package com.lam.dormitory.util;

import com.alibaba.fastjson.annotation.JSONField;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 统一的接口返回数据结构模版
 *
 * @author Roger_Luo
 */
@Data
public class ResponseTemplate {
    // 默认成功调用时返回的返回码
    public static final Integer SUCCESS_RETURN_CODE = 0;

    @ApiModelProperty(name = "返回码", value = "每次调用接口时，可能获得正确或错误的返回码，开发者可以根据返回码信息调试接口，排查错误。", example = "0")
    @JSONField(ordinal = 1)
    private int code;

    @ApiModelProperty(name = "错误提示", value = "如果接口调用发生错误，该参数会返回相应的错误信息，该错误信息已经实现国际化。", example = "OK")
    @JSONField(ordinal = 2)
    private String message;

    @ApiModelProperty(name = "返回的数据json", value = "如果接口会返回数据，所有相关的数据都会放到该参数里面，数据结构以及参数类型请根据具体接口文档界定。")
    @JSONField(ordinal = 3)
    private Object data;

    @ApiModelProperty(name = "总页数", value = "总页数。")
    private Long totalPages;

    public ResponseTemplate(int code, String message) {
        this.code = code;
        this.message = message;
        this.data = null;
    }

    public ResponseTemplate(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResponseTemplate(int code, String message, Object data, Long totalPages) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.totalPages = totalPages;
    }


}
